********************************************************************************
** Cederman, Galano, Girardin and Schvitz. War Did Make States.
** Article prepared for International Organization
** August 18, 2022
**
** Stata master do-file
** 
** Sets file paths and runs various replication scripts
********************************************************************************

// This do file runs both state and dyad level scripts for the Tilly project using Abramsonmax, Abramsonmax1400 and Centennia data as input
// Each dataset are run with the following main do files:
//   data_prep1.do
//   data_prep_dyadic.do
//   data_prep2.do
//   analysis_states.do  
//   analysis_dyads.do
// or variations thereof.
// These do files put various intermediate results into the respective intermediate and output directories.



********************************************************************************
******************************************************************************** 
** ONLY EDIT THIS LINE TO SET ROOT DIR, REST DEFINED AS RELATIVE PATHS

** Absolute path to the data, by default obtained through the current working directory
// global ROOT "~/War Did Make States/"
global ROOT : pwd

********************************************************************************
** DATA PREP AND ANALYSES: MAIN DATASET
********************************************************************************

** Define relevant paths
global INPUTDIR "."
global INPUTFILE "AbramsonmaxClipped.csv"
global INPUTFILED "AbramsonmaxClippedDyadic.csv"
global INTERMEDIATEDIR "IntermediateFiles/"
global OUTPUTDIR "Output/"
global FIRSTYEAR "1490"
cd $ROOT
capture mkdir $INTERMEDIATEDIR
capture mkdir $OUTPUTDIR

** Data prep: State-level data
cd $ROOT
do "data_prep1.do"

** Data prep: Dyadic data
cd $ROOT
do "data_prep_dyadic.do"

** Data prep: State-level data again
cd $ROOT
do "data_prep2.do"

** Analysis: State-level
cd $ROOT
do "analysis_states.do"

** Analysis: Dyadic level
cd $ROOT
do "analysis_dyads.do"


********************************************************************************
** DATA PREP AND ANALYSES: ABRAMSONMAX1400
********************************************************************************

** Overwrite relevant paths
global INPUTDIR "."
global INPUTFILE "Abramsonmax1400Clipped.csv"
global INPUTFILED "Abramsonmax1400ClippedDyadic.csv"
global INTERMEDIATEDIR "IntermediateFiles1400"
global OUTPUTDIR "Output1400/"
global FIRSTYEAR "1400"
cd $ROOT
capture mkdir $INTERMEDIATEDIR
capture mkdir $OUTPUTDIR

** Data prep: State-level data
cd $ROOT
do "data_prep1.do"

** Data prep: Dyadic data
cd $ROOT
do "data_prep_dyadic.do"

** Data prep: State-level data again
cd $ROOT
do "data_prep2.do"

** Analysis: State-level
** cd $ROOT
** do "analysis_states.do"

** Analysis: Dyadic level (Tables A5 and A11)
cd $ROOT
do "analysis_dyads_1400.do"


********************************************************************************
** DATA PREP AND ANALYSES: CENTENNIA
********************************************************************************


** Overwrite relevant paths
global INPUTDIR "."
global INPUTFILE "CentenniaClipped.csv"
global INPUTFILED "CentenniaClippedDyadic.csv"
global INTERMEDIATEDIR "IntermediateFilesCentennia"
global OUTPUTDIR "OutputCentennia/"
global FIRSTYEAR "1490"
cd $ROOT
capture mkdir $INTERMEDIATEDIR
capture mkdir $OUTPUTDIR

cd $ROOT
cd $INPUTDIR
insheet using "CentenniaClipped.csv" , clear
cd $ROOT
cd $INTERMEDIATEDIR
save centennia_coast, replace


** Data prep: State-level data
cd $ROOT
do "data_prep_cent1.do"

** Data prep: Dyadic data
cd $ROOT
do "data_prep_dyadic_cent.do"

** Data prep: State-level data again
cd $ROOT
do "data_prep_cent2.do"

** Analysis: State-level
cd $ROOT
do "analysis_states_cent.do"

** Analysis: Dyadic level (Tables A12 and A13)
** cd $ROOT
** do "analysis_dyads.do"

cd $ROOT
do "analysis_dyads_cent.do"
